<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/24 0024
 * Time: 14:14
 */
namespace app\index\controller;
use think\Controller;
use think\Cache\driver\Redis;
class RedisTest extends Controller {
    const REDIS_SERVER_IP = "115.159.161.24";
    protected $redis;
    protected $username;
    protected $password="ZHANG1212";

    public function _initialize()
    {
        $config = [
            'host'       => self::REDIS_SERVER_IP,
            'port'       => 6379,
            'password'   => $this->password,
            'select'     => 0,
            'timeout'    => 0,
            'expire'     => 0,
            'persistent' => false,
            'prefix'     => '',
        ];
        $this->redis = new Redis($config);
    }
    public function index()
    {
        dump($this->redis->HashGet('NAME'));
        dump($this->redis->get('name'));exit;
    }
    //模拟商品入库
    public function GoodsAddRedis()
    {
        for($i=0;$i<100;$i++){
            //商品用list进行存储。
            $this->redis->lpush('goods',1);
        }
        echo $this->redis->llen('goods');
    }
}